!(function () {
    console.log('custom-login');
    console.log('custom-login',BI.i18nText("Fine-plugin-CustomLoginPage-test"));
    var syncAjax = function (n) {
        n = n || {};
        var t = Dec.fineServletURL + n.url, e = BI.Cache.getCookie(DecCst.Cookie.TOKEN);
        e && (n.headers = n.headers || {}, n.headers.Authorization = "Bearer " + e), $.support.cors = !0, $.ajax({
            url: t,
            type: n.type,
            headers: n.headers,
            contentType: "application/json",
            data: "GET" === n.type ? null : JSON.stringify(n.data),
            dataType: "json",
            cache: !1,
            async: !1,
            error: function () {
                BI.Msg.toast("ajax error !", "warning")
            },
            complete: function (t, e) {
                "success" === e && BI.isFunction(n.success) && n.success(BI.jsonDecode(t.responseText)), BI.isFunction(n.complete) && n.complete(BI.jsonDecode(t.responseText), e)
            }
        })
    };
    var config = {};
    syncAjax({
        url: "/url/getConfig",
        type: "GET",
        data: "",
        success: function (res) {
            if (res.success) {
                config = JSON.parse(res.data);
                if (!config) {
                    config = {};
                }
            }
            var Item = BI.inherit(BI.Widget, {
                props: {
                    baseCls: "dec-login-item",
                    iconCls: "",
                    watermark: "",
                    inputType: "text",
                    value: ""
                },

                render: function () {
                    var self = this, o = this.options;
                    return {
                        type: "bi.vertical",
                        items: [
                            {
                                type: "bi.htape",
                                height: 36,
                                items: [
                                    {
                                        type: "bi.vertical_adapt",
                                        cls: "item-icon " + o.iconCls,
                                        invisible: o.iconCls === "",
                                        width: o.iconCls === "" ? 0 : 26,
                                        items: [{
                                            type: "bi.center_adapt",
                                            items: [{
                                                type: "bi.icon"
                                            }]
                                        }]
                                    },
                                    {
                                        type: "bi.absolute",
                                        items: [
                                            {
                                                el: {
                                                    type: "bi.input",
                                                    element: "<input type='" + o.inputType + "' placeholder='" + o.watermark + "'/>",
                                                    allowBlank: true,
                                                    value: o.value,
                                                    ref: function (_ref) {
                                                        self.editor = _ref;
                                                    },
                                                    listeners: [{
                                                        eventName: BI.Input.EVENT_FOCUS,
                                                        action: function () {
                                                            self.hideError();
                                                        }
                                                    }, {
                                                        eventName: BI.Input.EVENT_BLUR,
                                                        action: function () {
                                                            self.fireEvent("EVENT_BLUR");
                                                        }
                                                    }]
                                                },
                                                // DEC-2582 edge下tab键时会产生偏移
                                                top: 0, right: 0, bottom: 0, left: 0
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                type: "bi.label",
                                cls: "bi-border-top",
                                text: "",
                                height: 24,
                                ref: function (_ref) {
                                    self.lineRow = _ref;
                                }
                            },
                            {
                                type: "bi.label",
                                invisible: true,
                                height: 24,
                                textAlign: "left",
                                cls: "bi-border-top error",
                                ref: function (_ref) {
                                    self.errorRow = _ref;
                                }
                            }
                        ]
                    };
                },

                showError: function (text) {
                    this.errorRow.visible();
                    this.errorRow.setText(text);
                    this.lineRow.invisible();
                },

                hideError: function () {
                    this.errorRow.invisible();
                    this.errorRow.setText("");
                    this.lineRow.visible();
                },

                getValue: function () {
                    return this.editor.getValue() + "";//其他地方的实现都和默认的一样，只是这边返回值时候多增加一个后缀
                }
            });
            BI.shortcut("dec.login.input.item.plugin", Item);//注册自己的组件，
            BI.config("dec.login.input.item", function (widget) {
                widget.type = "dec.login.input.item.plugin";//直接修改掉组件的type，这样就会实际使用的是自己定义的组件
                return widget;
            });

            //
            var loginInput = BI.inherit(BI.Widget, {
                props: {baseCls: "dec-login-login"}, _store: function () {
                    return BI.Models.getModel("dec.model.login.login")
                }, watch: {
                    supportForgetPwd: function (e) {
                        this.forgetPasswordRow.setVisible(e)
                    }, needSlider: function (e) {
                        this.sliderBar.setVisible(e), this.sliderError.setVisible(e)
                    }
                }, render: function () {
                    var t = this;
                    this.options;
                    return {
                        type: "bi.absolute",
                        items: [{
                            el: {
                                type: "bi.vertical",
                                items: [{
                                    type: "dec.login.login.item",
                                    $testId: "dec-login-username",
                                    iconCls: "login-username-font",
                                    tgap: 50,
                                    watermark: BI.i18nText(config.userPlaceholder),
                                    ref: function (e) {
                                        t.usernameRow = e
                                    },
                                    listeners: [{
                                        eventName: "EVENT_BLUR", action: function () {
                                            t.store.checkUsername(this.getValue())
                                        }
                                    }]
                                }, {
                                    type: "dec.login.login.item",
                                    $testId: "dec-login-password",
                                    iconCls: "login-password-font",
                                    watermark: BI.i18nText(config.pswPlaceholder),
                                    inputType: "password",
                                    ref: function (e) {
                                        t.passwordRow = e
                                    }
                                }, {
                                    type: "bi.horizontal_auto",
                                    items: [{
                                        type: "dec.login.slider", invisible: !0, ref: function (e) {
                                            t.sliderBar = e
                                        }, listeners: [{
                                            eventName: "EVENT_SUCCESS", action: function () {
                                                t.sliderError.setText("")
                                            }
                                        }, {
                                            eventName: "EVENT_FAIL", action: function () {
                                                t.sliderError.setText(BI.i18nText("Dec-Login_Need_Slider"))
                                            }
                                        }]
                                    }]
                                }, {
                                    type: "bi.label",
                                    $testId: "dec-login-slider-error-text",
                                    invisible: !0,
                                    textAlign: "left",
                                    height: 20,
                                    cls: "login-error",
                                    ref: function (e) {
                                        t.sliderError = e
                                    }
                                }, {
                                    type: "bi.left_right_vertical_adapt",
                                    bgap: 30,
                                    items: {
                                        left: [{
                                            type: "bi.multi_select_item",
                                            $testId: "dec-login-remember",
                                            lgap: -5,
                                            height: 16,
                                            text: BI.i18nText("Dec-Login_Remember"),
                                            logic: {dynamic: !0},
                                            ref: function (e) {
                                                t.rememberRow = e
                                            }
                                        }],
                                        right: [{
                                            type: "bi.button",
                                            $testId: "dec-login-forget-password",
                                            clear: !0,
                                            height: 16,
                                            invisible: !this.model.supportForgetPwd,
                                            text: BI.i18nText("Dec-Basic_Forget_Password"),
                                            ref: function (e) {
                                                t.forgetPasswordRow = e
                                            },
                                            handler: function () {
                                                t.store.setSelectedTab(DecCst.Login.Tabs.FORGET_PASSWORD)
                                            }
                                        }].concat(this._createItems())
                                    }
                                }, {
                                    type: "bi.horizontal_auto",
                                    items: [{
                                        type: "bi.button",
                                        cls: "login-button",
                                        text: BI.i18nText("Dec-Basic_Login"),
                                        width: 190,
                                        height: 40,
                                        handler: function () {
                                            t._start()
                                        }
                                    }]
                                }, {
                                    el: {
                                        type: "bi.vertical",
                                        $testId: "dec-login-logged-chang-text",
                                        cls: "login-error",
                                        invisible: !0,
                                        scrolly: !1,
                                        items: [{
                                            type: "bi.text",
                                            tagName: "span",
                                            whiteSpace: "normal",
                                            text: BI.i18nText("Dec-Login_Other_Logged_Tip")
                                        }, {
                                            type: "bi.text",
                                            $testId: "dec-login-logged-chang-password",
                                            tagName: "span",
                                            cls: "password-btn",
                                            text: BI.i18nText("Dec-Login_Change_Password"),
                                            handler: function () {
                                                t.model.isNeedVerify ? t.store.setSelectedTab(DecCst.Login.Tabs.VERIFY_BING) : t.store.setSelectedTab(DecCst.Login.Tabs.PASSWORD_OLD)
                                            }
                                        }],
                                        ref: function (e) {
                                            t.loginErrorRow = e
                                        }
                                    }, tgap: 20
                                }, {
                                    el: {
                                        type: "bi.text",
                                        $testId: "dec-login-logged-text",
                                        cls: "login-error",
                                        invisible: !0,
                                        whiteSpace: "normal",
                                        text: BI.i18nText("Dec-Login_Normal_Other_Logged_Tip"),
                                        ref: function (e) {
                                            t.loginNormalErrorRow = e
                                        }
                                    }, tgap: 20
                                }]
                            }, top: 0, right: 40, bottom: 0, left: 40
                        }]
                    }
                }, mounted: function () {
                    var t = this;
                    this.store.initData(), this.element.keyup(function (e) {
                        13 === e.keyCode && t._start()
                    })
                }, _createItems: function () {
                    return BI.map(BI.Constants.getConstant("dec.constant.login.way.extend"), function (e, t) {
                        return {type: t.cardType}
                    })
                }, _start: function () {
                    var t = this, e = this.usernameRow.getValue(), i = this.passwordRow.getValue(),
                        o = this.rememberRow.isSelected() ? -2 : -1, n = this.sliderBar.getStatus();
                    t.loginErrorRow.invisible(), t.loginNormalErrorRow.invisible(), "" !== e ? "" !== i ? !n.show || n.status ? (this.store.setLoginInfo({
                        username: e,
                        validity: o,
                        phone: "",
                        captcha: ""
                    }), this.store.login({
                        username: e,
                        password: BI.aesEncrypt(i, Dec.system.frontSeed),
                        validity: o,
                        sliderToken: this.model.sliderToken,
                        origin: Dec.Utils.getUrlQuery("origin"),
                        encrypted: !0
                    }, function (e) {
                        e.data && e.data.accessToken ? t.fireEvent("EVENT_LOGIN", e.data) : BI.bind(BI.Services.getService("dec.service.login.login").getHandler(e.errorCode), t)(e)
                    })) : this.sliderError.setText(BI.i18nText("Dec-Login_Need_Slider")) : this.passwordRow.showError(BI.i18nText("Dec-Error_Password_Not_Null")) : this.usernameRow.showError(BI.i18nText("Dec-Error_Username_Not_Null"))
                }
            });
            BI.shortcut("dec.login.login.plugin", loginInput);
            BI.config("dec.login.login", function (widget) {
                widget.type = "dec.login.login.plugin";
                return widget;
            });
            //
            var loginCard = BI.inherit(BI.Widget, {
                props: {baseCls: "dec-login"}, _store: function () {
                    return BI.Models.getModel("dec.model.login")
                }, watch: {}, render: function () {
                    var t = this, e = this.model.loginConfig;
                    return BI.Services.getService("dec.service.login").initStyles(), {
                        type: (config.loginLeft || config.loginTop) ? "bi.absolute" : "bi.center_adapt",
                        cls: "dec-login-background",
                        items: [
                            {
                                left: config.loginLeft ? config.loginLeft : 0,
                                top: config.loginTop ? config.loginTop : 0,
                                el: {
                                    // type: (config.loginLeft)?"bi.absolute":"bi.htape",
                                    type: "bi.htape",
                                    // left: 100,
                                    cls: "login-card",
                                    width: 720,
                                    height: 380,
                                    items: [{
                                        type: "bi.absolute",
                                        $testId: "dec-login-img-background",
                                        cls: "dec-login-img-background",
                                        items: [{
                                            el: {
                                                type: "bi.horizontal_auto",
                                                cls: "dec-login-left-color",
                                                items: [{
                                                    el: {
                                                        type: "bi.center_adapt",
                                                        items: [{
                                                            type: "bi.img",
                                                            src: BI.isEmpty(e.loginLogoImgId) ? Dec.resourceURL + "resources/logo.png" : Dec.fineServletURL + "/login/image/" + e.loginLogoImgId,
                                                            height: 50,
                                                            width: "auto"
                                                        }]
                                                    }, tgap: 140, bgap: 30
                                                }, {type: "bi.label", cls: "dec-font-weight-bold", text: e.loginTitle}]
                                            }, top: 0, right: 0, bottom: 0, left: 0
                                        }],
                                        ref: function (e) {
                                            t.loginLeft = e
                                        }
                                    }, {type: "dec.login.index", cls: "bi-card", width: 270}]
                                }

                            }

                        ]
                    }
                }, mounted: function () {
                    var e = this.model.loginConfig;
                    e.loginImg && this.loginLeft.element.css("backgroundImage", "url(" + Dec.fineServletURL + "/login/image/" + e.loginImgId + ")")
                }
            });
            BI.shortcut("dec.login.plugin", loginCard);
            BI.config("dec.login", function (widget) {
                widget.type = "dec.login.plugin";
                return widget;
            });
            // 自定义文本
            var textEle = BI.createWidget({
                type: "bi.label",
                text: config.customText,
            });
            BI.createWidget({
                element: "#wrapper",
                type: "bi.absolute",
                items: [textEle,]
            });
            textEle.element.css('zIndex', 99999);
            textEle.element.css('fontSize', config.textSize ? config.textSize : 12);
            textEle.element.css('color', config.textColor ? config.textColor : "#000");
            textEle.element.css('top', config.textTop ? config.textTop : 0);
            textEle.element.css('left', config.textLeft ? config.textLeft : 0);
            // 自定义图片
            if (config.imageId) {
                var imgEle = BI.createWidget({
                    type: "bi.img",
                    src: Dec.fineServletURL + "/login/image/" + config.imageId,
                    height: config.imageHeight?config.imageHeight:100,
                    width: config.imageWidth?config.imageWidth:"auto",
                    // width: "auto"
                });
                BI.createWidget({
                    element: "#wrapper",
                    type: "bi.absolute",
                    items: [imgEle,]
                });
                imgEle.element.css('zIndex', 99998);
                imgEle.element.css('top', config.imageTop ? config.imageTop : 0);
                imgEle.element.css('left', config.imageLeft ? config.imageLeft : 0);
            }
        }
    });

}());